//
//  UserModel.swift
//  chat
//
//  Created by 1 on 2023/4/1.
//

import ObjectMapper

class UserModel: BaseModel {

    var user_nickname: String = ""
    var user_vip: String?
    var user_vip_expire_time: String?//"2023-06-30 17:09:07"
    var user_mobile: String?
//    var user_avatar: String?
    var user_name: String?
    var user_sex: String? //性别 0-未知 1-男 2-女
    
    var user_avatar: String{//用户头像，根据性别获取本地图片
        get{
            if let user_sex = user_sex{
                if("1" == user_sex){
                    return "img_head_default_man"
                }else if("2" == user_sex){
                    return "img_head_default_woman"
                }else{
                    return "img_head_default_wsz"
                }
            }else{
                return "img_head_default_wsz"
            }
        }
    }
    
    var user_sexString: String{
        get{
            if let user_sex = user_sex{
                if("1" == user_sex){
                    return "男"
                }else if("2" == user_sex){
                    return "女"
                }else{
                    return "保密"
                }
            }else{
                return "保密"
            }
        }
    }
    
    var vip:Bool{
        get{
            (user_vip != nil) && user_vip == "1"
        }
    }
    
    var mobileBind:Bool{
        get{
            (user_mobile != nil) && !user_mobile!.isEmpty
        }
    }
    
    var showLocalNickName:String{
        get{
            if(user_nickname.isEmpty){
                if(mobileBind){
                    return "昵称未设置"
                }else{
                    return "游客"
                }
            }else{
                return user_nickname
            }
        }
    }
    
    
    var vip_format_expire_time:String{
        if let user_vip_expire_time = user_vip_expire_time{
            return user_vip_expire_time.components(separatedBy: " ").first ?? ""
        }else{
            return ""
        }
    }

    public required init?(map: Map) {
       super.init(map: map)
    }

    override func mapping(map: Map) {
        user_nickname <- map["user_nickname"]
        user_vip <- map["user_vip"]
        user_vip_expire_time <- map["user_vip_expire_time"]
        user_mobile <- map["user_mobile"]
//        user_avatar <- map["user_avatar"]
        user_name <- map["user_name"]
        user_sex <- map["user_sex"]
    }
}


